package com.cloud.consumer.ribbon;

import com.cloud.consumer.config.CustomRibbonClientConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.cloud.netflix.ribbon.RibbonClientConfiguration;
import org.springframework.cloud.netflix.ribbon.RibbonClients;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

@SpringBootApplication
@EnableEurekaClient
@EnableDiscoveryClient
@EnableHystrix
@EnableHystrixDashboard
@EnableCircuitBreaker
//name=服务提供者的instanceName,configuration指定Ribbon的配置类
//@RibbonClient(name = "server-producer", configuration = CustomRibbonClientConfig.class)
@RibbonClients(
        defaultConfiguration= RibbonClientConfiguration.class,
        value= {
                @RibbonClient(name="producer",configuration= CustomRibbonClientConfig.class)
        })
public class SpringcloudServiceRibbonApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringcloudServiceRibbonApplication.class, args);
    }

    @Bean
    @LoadBalanced  //开启负载均衡（默认轮询访问服务生产者）
    RestTemplate restTemplate() {
        return new RestTemplate();
    }

}
